<?php

namespace app\model;

use think\facade\Db;
use think\Model;

class ProductReturnCategory extends Model {

    protected $table ="product_return_category";

    protected $pk = 'product_return_category_id';



    /*
   * 获取total
   * */
    public function getTotal($where=[]){
        return Db::name('product_return_category')->where($where)->count();
    }


    /*
     * 获取list
     * */
    public function getList($where=[],$page = null,$limit = null,$orderField = null,$orderType = "ASC"){

        $obj =  Db::name('product_return_category')->field("return_category_id")->where($where);


        if(!empty($page) && !empty($limit)){
            $obj = $obj->page($page, $limit);
        }

        if(!empty($orderField) && !empty($orderType)){
            $obj = $obj->order($orderField, $orderType);
        }

        $list = $obj->select();

        $baseAftersalesOptions = new BaseReturnCategory();
        if($list){
            $return = [];
            foreach($list as $item){
                $return[] = $baseAftersalesOptions->getInfo($item['return_category_id']);
            }
            return $return;
        }
        return [];
    }



    /*
     * 获取商品售后服务属性列表
     * */
    public function getProductReturnCategory($product_id){
        $where =[];
        $where[] = ["product_id","=",$product_id];
        return $this->getList($where);
    }
}